package com.kirk.cts.core.base.pagination;

import com.kirk.cts.core.base.pagination.mybatis.MyBatisPersistence;

import java.util.List;

/**
 * 持久层服务实现代表类
 * <p/>
 * 框架持久层服务的总实现类，组合了JDBC/SQLMAP三种持久服务实现。
 */
public class PersistServiceDelegate implements PersistService {
    /**
     * MyBatis持久服务
     */
    private MyBatisPersistence myBatisPersistence;


    @Override
    public int insertBySqlMap(String sqlId, Object parameterObject) {
        return myBatisPersistence.save(sqlId, parameterObject);
    }

    @Override
    public int updateBySqlMap(String sqlId, Object parameterObject) {
        return myBatisPersistence.modify(sqlId, parameterObject);
    }

    @Override
    public int deleteBySqlMap(String sqlId, Object parameterObject) {
        return myBatisPersistence.remove(sqlId, parameterObject);
    }

    @Override
    public Object findObjectBySqlMap(String sqlId, Object parameterObject) {
        return myBatisPersistence.get(sqlId, parameterObject);
    }

    @Override
    public List<?> findListBySqlMap(String sqlId, Object parameterObject) {
        return myBatisPersistence.getList(sqlId, parameterObject);
    }

    @Override
    public PaginationSupport<?> findPaginatedListBySqlMap(String sqlId,
                                                          Object parameterObject, int offset, int limit) {
        return myBatisPersistence.getPaginatedResult(sqlId, parameterObject, offset, limit);
    }

    public MyBatisPersistence getMyBatisPersistence() {
        return myBatisPersistence;
    }

    public void setMyBatisPersistence(MyBatisPersistence myBatisPersistence) {
        this.myBatisPersistence = myBatisPersistence;
    }


}
